package 牛客网_N.动态规划.魔术索引2_4;

import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int n = Integer.parseInt(in.nextLine());
		String str = in.nextLine();
		String[] dataStr = str.split(" ");
		int[] a = new int[n];
		for(int i = 0; i < n; i++){
			a[i] = Integer.parseInt(dataStr[i]);
		}
		
		System.out.println(findMagicIndex(a, n));
	}
	
	public static boolean findMagicIndex(int[] A, int n){
		int i = 0;
		for(;i < n;){
			if(A[i] == i){
				return true;
			}else if(A[i] > i){
				i = A[i];
			}
		}
		return false;
	}
}
